#include <stdio.h>
extern "C"
{
#include <lualib.h>
#include <lauxlib.h>
}
void nlua_stack_dump(lua_State* L)
{
    auto n = lua_gettop(L);
    fprintf(stderr, " ---------------- Stack Dump ----------------\n");
    for (int i = n; i > 0; i--) {
        switch (lua_type(L, i)) {
        case LUA_TSTRING: fprintf(stderr, "%d: string\n", i); break;

        case LUA_TNUMBER: fprintf(stderr, "%d: number\n", i); break;

        case LUA_TBOOLEAN: fprintf(stderr, "%d: boolean\n", i); break;

        case LUA_TNIL:
        case LUA_TNONE: fprintf(stderr, "%d: nil\n", i); break;

        case LUA_TTABLE: fprintf(stderr, "%d: table\n", i); break;

        case LUA_TFUNCTION: fprintf(stderr, "%d: function\n", i); break;

        case LUA_TUSERDATA:
        case LUA_TLIGHTUSERDATA: fprintf(stderr, "%d: userdata\n", i); break;

        case LUA_TTHREAD: fprintf(stderr, "%d: thread\n", i); break;

        default: fprintf(stderr, "%d: unknown\n", i); break;
        }
    }
    fprintf(stderr, " ---------------- Stack Dump End ----------------\n");
}
